package xyz.mumuwei.youthcourseserver.controller;


import lombok.RequiredArgsConstructor;
import org.quartz.SchedulerException;
import org.springframework.web.bind.annotation.*;
import xyz.mumuwei.youthcourseserver.common.dto.PageDto;
import xyz.mumuwei.youthcourseserver.common.lang.Result;
import xyz.mumuwei.youthcourseserver.service.StudentExperienceService;

import javax.validation.constraints.NotNull;

/**
 * @author mumuwei
 * @since 2022-02-19
 */
@RestController
@RequestMapping("/experience")
@RequiredArgsConstructor
public class StudentExperienceController {

    final StudentExperienceService studentService;

    /**
     * 学生预约体验课程
     */
    @PostMapping("/student/{courseId}")
    public Result reserve(@PathVariable @NotNull(message = "课程信息不但能为空!") Integer courseId, @RequestAttribute Integer uid) throws SchedulerException {
        return studentService.reserveCourseByStudent(courseId, uid);
    }

    /**
     * 根据课程id查询 学生 是否预约体验该课程
     * @param courseId 课程id
     * @param uid 学生账户 id
     * @return 返回查询结果
     */
    @GetMapping("/check-course/{courseId}")
    public Result checkReserveByCourseId(@PathVariable @NotNull(message = "") Integer courseId, @RequestAttribute Integer uid) {
        return studentService.checkReserveByCourseId(courseId, uid);
    }

    /**
     *  根据课程 Id 取消体验预约
     */
    @GetMapping("/del_{courseId}")
    public Result delete(@PathVariable @NotNull(message = "课程Id不能为空") Integer courseId, @RequestAttribute Integer uid) throws SchedulerException {
        return studentService.deleteByCourseId(courseId, uid);
    }

    /**
     * 根据学生账户id获取预约课程列表
     */
    @GetMapping("/student/list")
    public Result getStudentExperienceList(@RequestAttribute Integer uid) {
        return studentService.getStudentExperienceList(uid);
    }

    /**
     * 根据课程id获取预约体验课程学生列表(不分页)
     */
    @GetMapping("/list/{courseId}")
    public Result getExperienceListByCourseId(@PathVariable Integer courseId) {
        return studentService.getExperienceListByCourseId(courseId);
    }

    /**
     * 根据课程id获取预约体验课程学生列表(分页)
     */
    @GetMapping("/page/{courseId}")
    public Result getExperiencePageByCourseId(@PathVariable Integer courseId, PageDto pageDto) {
        return studentService.getExperiencePageByCourseId(courseId, pageDto);
    }
}

